package com.rich.live.controller;

import com.rich.common.result.CommonResponse;
import com.rich.common.result.ResultData;
import com.rich.live.pojo.TbLive;
import com.rich.live.service.LiveService;
import com.rich.live.vo.LiveVo;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author hu
 * @version 1.0
 * @date 2021/08/14 18:51
 */
@RestController
@RequestMapping("/live")
@CrossOrigin
public class LiveController {

    private final LiveService liveService;

    public LiveController(LiveService liveService) {
        this.liveService = liveService;
    }

    /**
     * 不限、正在直播、精彩回放查询
     *
     * @param status
     * @return List<TbLive>
     */
    @GetMapping("/allLive")
    public List<TbLive> allLive(String status) {
        return liveService.allLive(status);
    }

    /**
     * 添加直播
     *
     * @param live
     * @param token
     */
    @PostMapping("/addLive")
    public void addLive(@RequestBody TbLive live, @RequestParam("token") String token) {
        try {
            liveService.addLive(live, token);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }



    /**
     * 开启关闭直播 是否违规
     *
     * @param id
     * @param violation
     */
    @PutMapping("/onAndOff/{id}/{violation}")
    public void onAndOff(@PathVariable("id") Long id, @PathVariable("violation") String violation) {
        try {
            liveService.onAndOff(id, violation);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    /**
     * 查询当前直播信息
     *
     * @param id
     * @return TbLive
     */
    @GetMapping("/findOne")
    public TbLive findOne(Long id) {
        return liveService.findOne(id);
    }

    /**
     * 逻辑删除
     *
     * @param id
     */
    @DeleteMapping("/deleteById/{id}")
    public void deleteById(@PathVariable("id") Long id) {
        liveService.deleteById(id);
    }

    /**
     * 当前直播人和在线人数
     *
     * @param id
     * @return CommonResponse
     */
    @GetMapping("/liveDetails/{id}")
    public CommonResponse liveDetails(@PathVariable("id") Long id) {
        return liveService.liveDetails(id);
    }

    /**
     * 进入直播间 在线人数+1
     *
     * @param id
     */
    @PutMapping("/liveInfo/{id}")
    public void liveInfo(@PathVariable("id") Long id) {
        liveService.liveInfo(id);
    }

    /**
     * 退出直播间 在线人数-1
     *
     * @param id
     */
    @PutMapping("/liveExit/{id}")
    public void liveExit(@PathVariable("id") Long id) {
        liveService.liveExit(id);
    }
    /**
     * 拉流
     *
     * @param id
     * @return CommonResponse
     */
    @GetMapping("/la")
    public CommonResponse la(Long id) {
        return liveService.la(id);
    }

    /**
     * 查询
     *
     * @param live
     * @return ResultData
     */
    @GetMapping("/liveList")

    public ResultData liveList(@RequestBody LiveVo live) {
        return liveService.liveList(live);
    }

    /**
     * 精彩回放点击量
     *
     * @param id
     */
    @PutMapping("/updatePlayNum")
    public void updatePlayNum(Long id) {
        liveService.updatePlayNum(id);
    }


    /**
     * 开启直播
     *
     * @param id
     * @return
     */
    @GetMapping("/start")
    public TbLive start(Long id){
        return liveService.start(id);
    }

    /**
     * 直播结束 修改直播状态
     *
     * @param id
     * @param status
     */
    @PutMapping("/startStatusById/{id}/{status}")
    public void startStatusById(@PathVariable("id") Long id, @PathVariable("status") String status) {
        try {
            liveService.startStatusById(id, status);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
